-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy both indices and values #101
Conversation
Codecov Report
@@ Coverage Diff @@
## master #101 +/- ##
==========================================
+ Coverage 77.08% 77.48% +0.40%
==========================================
Files 18 18
Lines 1999 1999
==========================================
+ Hits 1541 1549 +8
+ Misses 458 450 -8
Continue to review full report at Codecov.
|
@andyferris my main concern here is defining the generic version of copy as: function Base.copy(d::AbstractDictionary, ::Type{T}) where {T}
out = similar(copy(keys(d)), T)
copyto!(out, d)
return out
end instead of: function Base.copy(d::AbstractDictionary, ::Type{T}) where {T}
out = similar(d, T)
copyto!(out, d)
return out
end It seems like this assumes a one-to-one mapping between Would it make sense to make |
Yeah that's one reason why it was implemented how it is, because this is a bit awkward. As it stands you'd almost not want an abstract definition, and instead force every dictionary implementation to define I think the proper fix here is to finish and merge #54 and then define it like: function Base.copy(d::AbstractDictionary, ::Type{T}) where {T}
out = similar_type(d, T)(copy(keys(d)))
copyto!(out, d)
return out
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andyferris would be nice to have it! Would you merge & release please? |
Sorry, this one slipped my mind and now I forget the status. Maybe worth just merging this without doing #54? That seems like a bigger issue (though very important, we are designing a |
Another yearly bump @andyferris ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reminder. Sometimes I sway either way about whether this should happen, or not, but I think users will appreciate this. (That said, I don't get much feedback on Dictionaries.jl beyond the occassional "it works").
Since this PR has been written, we have added UnorderedDictionary
which now also need a copy
method before we can merge.
""" | ||
copy(dict::AbstractDictionary) | ||
copy(dict::AbstractDictionary, ::Type{T}) | ||
|
||
Create a shallow copy of the values of `dict`. Note that `keys(dict)` is not copied, and | ||
therefore care must be taken that inserting/deleting elements. A new element type `T` can | ||
Create a shallow copy of the values of `dict`. A new element type `T` can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should say "values and indices of dict"?
Due to confilcts I've moved this to #136. |
Thanks again @mtfishman and @aplavin |
Fixes #98.